package com.hy.service.impl;

import com.hy.bean.Classify;
import com.hy.dao.ClassifyDao;
import com.hy.dao.impl.ClassifyDaoImpl;
import com.hy.service.ClassifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * (Classify)表服务实现类
 *
 * @author makejava
 * @since 2024-04-29 11:08:29
 */
@Service("classifyService")
public class ClassifyServiceImpl implements ClassifyService {

    private ClassifyDao classifyDao = new ClassifyDaoImpl();

    @Override
    public List<Classify> queryAll() throws Exception {
        return classifyDao.queryAll();
    }

    /**
     * 新增数据
     *
     * @param classify 实例对象
     * @return 实例对象
     */
    @Override
    public Classify insert(Classify classify) throws Exception {
        this.classifyDao.insert(classify);
        return classify;
    }

    /**
     * 修改数据
     *
     * @param classify 实例对象
     * @return 实例对象
     */
    @Override
    public Classify update(Classify classify) throws Exception {
        classifyDao.update(classify);
        return classify;
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(int id) throws Exception {
        BigDecimal count = classifyDao.count(id);
        if (count.compareTo(BigDecimal.ZERO) == 0) {
            classifyDao.deleteById(id);
        }
        return count.compareTo(BigDecimal.ZERO) > 0;
    }
}
